(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('apf.revokeStopPayment.createBankVerifyController', createBankVerifyController);
	createBankVerifyController.$inject = [ '$q', '$filter', '$scope', 'Constants', 'formatService', 'modalService', 'gridService', 'layoutConfig', 'validatorConfig', 'authService',
			'stopPaymentService', 'dateService', "arithService", 'commonService'];
	function createBankVerifyController($q, $filter, $scope, Constants, formatService, modalService, gridService, layoutConfig, validatorConfig, authService, stopPaymentService, dateService, arithService, commonService) {
		var ctrl = this, params = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.invPayLoad = {};
		ctrl.init = function() {
			ctrl.innerGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.member.tableConfigs.table);
			ctrl.innerGridOptions.data = 'vm.stopPayment.memberList';
			ctrl.innerGridOptions.enableRowHeaderSelection = false;
			authService.createBankVerify(params).then(function(response) {
				if (response.data && response.data.model && response.data.task) {
					ctrl.stopPayment= response.data.model;
					ctrl.stopPayment.taskId = response.data.task.taskId;
				}
			});
		};

		ctrl.createBankVerifyReject = function() {
			modalService.openPromptDialogs({
				'btnCallback' : {
					'ok' : function(comments) {
						ctrl.stopPayment.message = comments;
						authService.createBankVerifyReject(ctrl.stopPayment).then(rejectSuccessful, rejectFailed);
					}
				}
			});
		};

		ctrl.createBankVerifyApprove = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.approve', args : [ctrl.stopPayment.primaryKey]} ],
				'btnCallback' : {
					'ok' : function() {
						authService.createBankVerifyApprove(ctrl.stopPayment).then(approveSuccessful, approveFailed);
					}
				}
			});
		};

		function approveSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.approve' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('apf.workflow.wfTxn.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'apf.workflow.wfTxn.list',
					'params' : {}
				}]
			});
		}
		
		
		function approveFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}

		function rejectSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.reject' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('apf.workflow.wfTxn.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'apf.workflow.wfTxn.list',
					'params' : {}
				}]
			});
		}

		function rejectFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
		
	}
})(angular);
